package _thread_lock._threadpool;

/**
 * @Author: huangya
 * @Date: 2020/10/14
 * @Description:
 */
public class InternalTask implements Runnable {

    /** Runnable队列 */
    private final RunnableQueue runnableQueue;

    private volatile boolean running = true;

    public InternalTask(RunnableQueue runnableQueue) {
        this.runnableQueue = runnableQueue;
    }

    @Override
    public void run() {
        while(running && !Thread.currentThread().isInterrupted()){
            try {
                /** 从Runnable队列中获取Runnable对象 */
                Runnable task = runnableQueue.take();
                /** 执行Runnable对象的run方法 */
                task.run();
            } catch (InterruptedException e) {
                running = false;
                break;
            }
        }
    }

    public void stop(){
        this.running = false;
    }

}
